<?php


namespace core\lib;


use Exception;

class conf
{
    /*
     * 1 判断配置文件是否存在
     * 2 判断配置是否存在
     * 3 缓存配置
     * */
    static public $conf = [];

    static public function get($name, $file)
    {
        if (isset(self::$conf[$file])) {
            return self::$conf[$file][$name];
        } else {
            $file_path = WJSSK . '/core/config/' . $file . '.php';
            if (is_file($file_path)) {
                $conf = include $file_path;
                if (isset($conf[$name])) {
                    self::$conf[$file] = $conf;
                    return $conf[$name];
                } else {
                    throw new Exception('未找到配置文件' . $file_path . '中的配置项' . $name);
                }
            } else {
                throw new Exception('未找到配置文件' . $file_path);
            }
        }
    }

    static public function all($file)
    {
        if (isset(self::$conf[$file])) {
            return self::$conf[$file];
        } else {
            $file_path = WJSSK . '/core/config/' . $file . '.php';
            if (is_file($file_path)) {
                $conf = include $file_path;
                self::$conf[$file] = $conf;
                return $conf;
            } else {
                throw new Exception('未找到配置文件' . $file_path);
            }
        }
    }
}